///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package summit.data
{

import flash.net.URLVariables;
	
/**
 * The <code>AccountToken</code> class is used as a general key for Basecamp 
 * interactions.
 */
public class AccountToken
{
	/** @private **/
	protected var _user:String;
	/** @private **/
	protected var _url:String;
	/** @private **/
	protected var _password:String;
	
	//-------------------------------------------------------------------------
	//
	//  Constructor
	//
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * <p>The <code>url<code> parameter should reflect the standard 
	 * URL for account access. The login action is treated special and 
	 * 'https' is automatically used. However, if https is specified in the 
	 * <code>url</code> parameter, the specified Basecamp account must support
	 * SSL.</p>
	 * 
	 * @param usr The user name to use for authentication.
	 * @param pass The password to use for authentication.
	 * @param url The URL used for the account - protocol (http vs. https) 
	 * should denote standard account access (https is only valid if 
	 * specifically enabled).
	 */
	public function AccountToken(usr:String, pass:String, url:String)
	{
		this._user = usr;
		this._password = pass;
		this._url = checkTrailingSlash(url);
	}

	/** @private strips a trailing / from the address... **/
	private function checkTrailingSlash(url:String):String
	{
		var i:int = url.length;
		i -= 1;
		
		if(url.charAt(i) == "/") url = url.substring(0, i);
			
		return url;
	}
	
	
	//-------------------------------------------------------------------------
	//
	//	Properties
	//
	//-------------------------------------------------------------------------
	
	/**
	 * Username for Basecamp account.
	 */
	public function get user():String
	{
		return this._user;		
	}
	
	/**
	 * Password for Basecamp account.
	 */
	public function get password():String
	{
		return this._password;	
	}
	
	/**
	 * Basecamp account URL.
	 * 
	 * <p>If SSL is enabled for the account, https should be provided 
	 * as part of the URL. If SSL is not enabled, use http.</p>
	 */
	public function get url():String
	{
		return this._url;	
	}
	
	
	/**
	 * Returns the URL with 'https' as the protocol.
	 */
	public function get secureURL():String
	{
		//trace(this._url.substr(0, 5));
		if(this._url.substr(0, 5) != "https")
			return "https://" + this._url.substr(7);
		else return this._url;
	}
	
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //